package com.upf1sh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.upf1sh.bean.Thingmodel;
import com.upf1sh.mapper.ThingmodelMapper;
import com.upf1sh.service.ThingmodelService;
import com.upf1sh.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Title: ThingmodelCtrl
 * @Package com.upf1sh.controller
 * @Author: ZhaoXu
 * @CreateTime: 2025/1/3 18:16
 */

@RestController
@RequestMapping("/thingmodel")
public class ThingmodelCtrl {

    @Autowired
    private ThingmodelService thingmodelService;

    @Autowired
    private ThingmodelMapper thingmodelMapper;
    @GetMapping("list")
    public Result list(Thingmodel thingmodel) {
        //List<Thingmodel> thingmodel1 = thingmodelService.getThingmodel(thingmodel);
        //Integer i = thingmodelMapper.selectCount(null);
        //Map map = new HashMap();
        //map.put("data", thingmodel1);
        //map.put("count", i);
        //return Result.ok().data(map);
        IPage<Thingmodel> thingmodelIPage = thingmodelService.selectPage(thingmodel);
        return Result.ok().data("data", thingmodelIPage);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Thingmodel thingmodel = thingmodelService.getThingmodelById(id);
        return Result.ok().data("data",thingmodel);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Thingmodel thingmodel) {
       return Result.ok().data("data",thingmodelService.addThingmodel(thingmodel));
    }

    @PostMapping("edit")
    public Result edit(@RequestBody Thingmodel thingmodel) {
        return Result.ok().data("data",thingmodelService.updateThingmodel(thingmodel));
    }

    @PostMapping("del/{id}")
    public Result del(@PathVariable Integer id) {
        return Result.ok().data("data",thingmodelService.deleteThingmodel(id));
    }

}
